#!/bin/sh
# This is the script running after PPTP VPN is connected for dd-wrt router using PPTP VPN manual connection mode

REMOTESUB=$(nvram get pptpd_client_srvsub)
REMOTENET=$(nvram get pptpd_client_srvsubmsk)
case "$6" in
 kelokepptpd)
  /sbin/route add -net $REMOTESUB netmask $REMOTENET dev $1
  /usr/sbin/iptables --insert OUTPUT --source 0.0.0.0/0.0.0.0 --destination $REMOTESUB/$REMOTENET --jump ACCEPT --out-interface $1
  /usr/sbin/iptables --insert INPUT --source $REMOTESUB/$REMOTENET --destination 0.0.0.0/0.0.0.0 --jump ACCEPT --in-interface $1
  /usr/sbin/iptables --insert FORWARD --source 0.0.0.0/0.0.0.0 --destination $REMOTESUB/$REMOTENET --jump ACCEPT --out-interface $1
  /usr/sbin/iptables --insert FORWARD --source $REMOTESUB/$REMOTENET --destination 0.0.0.0/0.0.0.0 --jump ACCEPT --in-interface $1
  /usr/sbin/iptables --insert FORWARD --protocol tcp --tcp-flags SYN,RST SYN --jump TCPMSS --clamp-mss-to-pmtu 
  if [ "$(/usr/sbin/nvram get pptpd_client_nat)" = "1" ]; then
      /usr/sbin/iptables --table nat --append POSTROUTING --out-interface $1 --jump MASQUERADE
  fi
  ;;
 *)
esac
/jffs/pptp/vpnup.sh pptp
exit 0
